﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LEET.LEETCommon.Model;
using LEET.CommonInterfaces.Compilers;
using LEET.CommonInterfaces.TestControls;

namespace ExpandCollapse
{
    public class ExpndColpsInstruction : Instruction
    {
        String element;
        String action;
        public ExpndColpsInstruction(String[] args) : base(args)
        {
            element = args[2];
            if (args[3].Trim() == "Expanded")
                action = "Expand()";
            else
                action = "Collapse()";
        }

        public static IAutomationActionResult ExpndColps()
        {
            //TODO
            return null;
        }

        public override String RenderStaticCall()
        {
            //TODO
            return "ExpandCollapse.ExpndColpsInstruction.ExpndColps()";
        }

        [Obsolete("This should now be replaced by RenderStaticCall", false)]
        protected override String MethodBody(AssertionSet asserts)
        {
            StringBuilder buf = new StringBuilder();
            String pattern = "ExpandCollapsePattern";
            buf.Append("                AutomationElement e = util.getElement(\"").Append(element).Append("\", Box.RootElement);\r\n");
            buf.Append("                ").Append("Object obj; ").Append(pattern).Append(" pattern;\r\n");
            buf.Append("                e.TryGetCurrentPattern(").Append(pattern).Append(".Pattern, out obj);\r\n");
            buf.Append("                pattern = obj as ").Append(pattern).Append(";\r\n");
            buf.Append("                if(pattern != null)\r\n");
            buf.Append("                    pattern.").Append(action).Append(";\r\n");
            buf.Append("                return new AutomationActionResult();\r\n");  //Needed for yield return.  Perhaps the state should be returned instead?
            return buf.ToString();
        }

        public override string PlainText()
        {
            if (args[3].Trim().EndsWith("Expand"))
                args[3] = "Expanded";
            else if (args[3].Trim().Equals("Collapse"))
                args[3] = "Collapsed";
            return "Target element " + args[2].Trim() + " " + args[3].Trim() + ".";
        }

        [Obsolete("This should now be replaced by RenderStaticCall", false)]
        protected override string RenderedMethodName(int i)
        {
            return "_" + i + "_ACTION";
        }
    }
}
